"""
@author: csy
@file: atm.py
@time: 2023/12/4 16:48
"""
# import json
#
# # 用户信息文件
# user_data_file = "user_data.json"
#
# def load_user_data():
#     try:
#         with open(user_data_file, "r") as file:
#             user_data = json.load(file)
#     except FileNotFoundError:
#         user_data = {}
#     return user_data
#
# def save_user_data(user_data):
#     with open(user_data_file, "w") as file:
#         json.dump(user_data, file)
#
# def login():
#     user_data = load_user_data()
#
#     username = input("请输入用户名: ")
#     password = input("请输入密码: ")
#
#     if username in user_data and user_data[username]["password"] == password:
#         print("登录成功！")
#         return username
#     else:
#         print("用户名或密码错误。")
#         return None
#
# def register():
#     user_data = load_user_data()
#
#     username = input("请输入用户名: ")
#     password = input("请输入密码: ")
#     initial_balance = float(input("请输入初始金额: "))
#
#     if username in user_data:
#         print("用户名已存在，请选择其他用户名。")
#     else:
#         user_data[username] = {"password": password, "balance": initial_balance}
#         save_user_data(user_data)
#         print("注册成功！")
#
# def deposit(username):
#     user_data = load_user_data()
#     amount = float(input("请输入存款金额: "))
#     user_data[username]["balance"] += amount
#     save_user_data(user_data)
#     print(f"存款成功！当前余额为：{user_data[username]['balance']}")
#
# def withdraw(username):
#     user_data = load_user_data()
#     amount = float(input("请输入取款金额: "))
#     if amount > user_data[username]["balance"]:
#         print("余额不足，无法取款。")
#     else:
#         user_data[username]["balance"] -= amount
#         save_user_data(user_data)
#         print(f"取款成功！当前余额为：{user_data[username]['balance']}")
#
# def transfer(username):
#     user_data = load_user_data()
#     recipient = input("请输入对方用户名: ")
#     if recipient not in user_data:
#         print("用户不存在，请检查用户名。")
#         return
#     amount = float(input("请输入转账金额: "))
#     if amount > user_data[username]["balance"]:
#         print("余额不足，无法转账。")
#     else:
#         user_data[username]["balance"] -= amount
#         user_data[recipient]["balance"] += amount
#         save_user_data(user_data)
#         print(f"转账成功！当前余额为：{user_data[username]['balance']}")
#
# def main():
#     while True:
#         print("\n1. 登录\n2. 注册\n3. 退出")
#         choice = input("请选择操作 (1/2/3): ")
#
#         if choice == "1":
#             username = login()
#             if username:
#                 while True:
#                     print("\na. 存钱\nb. 取钱\nc. 转账\nd. 退出")
#                     operation = input("请选择操作 (a/b/c/d): ")
#
#                     if operation == "a":
#                         deposit(username)
#                     elif operation == "b":
#                         withdraw(username)
#                     elif operation == "c":
#                         transfer(username)
#                     elif operation == "d":
#                         break
#                     else:
#                         print("无效的操作，请重新选择。")
#
#         elif choice == "2":
#             register()
#
#         elif choice == "3":
#             print("感谢使用，再见！")
#             break
#
#         else:
#             print("无效的选择，请重新选择。")
#
# if __name__ == "__main__":
#     main()


user_dict = {"root":{"password":"123456", "balance":1000}}
#添加一个admin用户  密码是:admin123   金额是:2000
user_dict["admin"] = {"password":"admin123", "balance":2000}
print(user_dict["root"]["balance"])

#更改atm存取款程序
#1、使用函数封装功能，程序流程方便内容不要放在函数里面
#2、在可能出现异常的地方添加异常捕获
#3、数据固化